#include "BspDeviceID.h"

#define CLOSE_LOOP_CAN_ID_BASE	0x0030
/*********************************************************************************************
  * @brief  BspDeviceID_IoConfig
  * @param  None
  * @retval None
	* @IO SW1-------------PC6
	* @IO SW2-------------PB12
	* @IO SW3-------------PB10
	* @IO SW4-------------PB11
  ********************************************************************************************/
void BspDeviceID_IoConfig(void)
{
	GPIO_InitTypeDef GPIOX;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD,ENABLE);
	
	GPIOX.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8 | GPIO_Pin_7 | GPIO_Pin_6 |
									GPIO_Pin_5 | GPIO_Pin_4 | GPIO_Pin_3;
	GPIOX.GPIO_Mode = GPIO_Mode_IN;
	GPIOX.GPIO_OType = GPIO_OType_PP;
	GPIOX.GPIO_PuPd = GPIO_PuPd_UP;
	GPIOX.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_Init(GPIOB,&GPIOX);
	
	GPIOX.GPIO_Pin = GPIO_Pin_2;
	GPIO_Init(GPIOD,&GPIOX);
}

/*********************************************************************************************
  * @brief  BspDeviceID_ReadID
  * @param  None
  * @retval uint8_t Device ID
	* @IO None
  ********************************************************************************************/
uint8_t BspDeviceID_ReadID(void)
{
	uint8_t DeviceID = 0;
	
	if((GPIOB->IDR & GPIO_Pin_9) == 0)
	{
		DeviceID |= 0X01;
	}
	if((GPIOB->IDR & GPIO_Pin_8) == 0)
	{
		DeviceID |= 0X02;
	}
	if((GPIOB->IDR & GPIO_Pin_7) == 0)
	{
		DeviceID |= 0X04;
	}
	if((GPIOB->IDR & GPIO_Pin_6) == 0)
	{
		DeviceID |= 0X08;
	}
	if((GPIOB->IDR & GPIO_Pin_5) == 0)
	{
		DeviceID |= 0X10;
	}
	if((GPIOB->IDR & GPIO_Pin_4) == 0)
	{
		DeviceID |= 0X20;
	}
	if((GPIOB->IDR & GPIO_Pin_3) == 0)
	{
		DeviceID |= 0X40;
	}
	if(DeviceID == 0)
		 DeviceID = 0X01;
	
	return DeviceID;
}
	


